<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Searches for all elements with given tag name in specified namespace</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="domdocument.getelementsbytagname.html">DOMDocument::getElementsByTagName</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="domdocument.importnode.html">DOMDocument::importNode</a></div>
 <div class="up"><a href="class.domdocument.html">DOMDocument</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="domdocument.getelementsbytagnamens" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMDocument::getElementsByTagNameNS</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">DOMDocument::getElementsByTagNameNS</span> &mdash; <span class="dc-title">
   Searches for all elements with given tag name in specified namespace
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domdocument.getelementsbytagnamens-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="class.domnodelist.html" class="type DOMNodeList">DOMNodeList</a></span> <span class="methodname"><strong>DOMDocument::getElementsByTagNameNS</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$namespaceURI</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$localName</code></span>
   )</div>

  <p class="para rdfs-comment">
   Returns a <a href="class.domnodelist.html" class="classname">DOMNodeList</a> of all elements with a given 
   local name and a namespace URI.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-domdocument.getelementsbytagnamens-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">namespaceURI</code></em></dt>

     <dd>

      <p class="para">
       The namespace URI of the elements to match on. 
       The special value <em>*</em> matches all namespaces.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">localName</code></em></dt>

     <dd>

      <p class="para">
       The local name of the elements to match on. 
       The special value <em>*</em> matches all local names.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domdocument.getelementsbytagnamens-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   A new <a href="class.domnodelist.html" class="classname">DOMNodeList</a> object containing all the matched 
   elements.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-domdocument.getelementsbytagnamens-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5285">
    <p><strong>Example #1 Get all the XInclude elements</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$xml&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOD<br /></span><span style="color: #DD0000">&lt;?xml&nbsp;version="1.0"&nbsp;?&gt;<br />&lt;chapter&nbsp;xmlns:xi="http://www.w3.org/2001/XInclude"&gt;<br />&lt;title&gt;Books&nbsp;of&nbsp;the&nbsp;other&nbsp;guy..&lt;/title&gt;<br />&lt;para&gt;<br />&nbsp;&lt;xi:include&nbsp;href="book.xml"&gt;<br />&nbsp;&nbsp;&lt;xi:fallback&gt;<br />&nbsp;&nbsp;&nbsp;&lt;error&gt;xinclude:&nbsp;book.xml&nbsp;not&nbsp;found&lt;/error&gt;<br />&nbsp;&nbsp;&lt;/xi:fallback&gt;<br />&nbsp;&lt;/xi:include&gt;<br />&nbsp;&lt;include&gt;<br />&nbsp;&nbsp;This&nbsp;is&nbsp;another&nbsp;namespace<br />&nbsp;&lt;/include&gt;<br />&lt;/para&gt;<br />&lt;/chapter&gt;<br /></span><span style="color: #007700">EOD;<br /></span><span style="color: #0000BB">$dom&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;load&nbsp;the&nbsp;XML&nbsp;string&nbsp;defined&nbsp;above<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getElementsByTagNameNS</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.w3.org/2001/XInclude'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'*'</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$element</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'local&nbsp;name:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$element</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">localName</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">',&nbsp;prefix:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$element</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prefix</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
local name: include, prefix: xi
local name: fallback, prefix: xi
</pre></div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-domdocument.getelementsbytagnamens-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="domdocument.getelementsbytagname.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::getElementsByTagName()</a> - Searches for all elements with given local tag name</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="domdocument.getelementsbytagname.html">DOMDocument::getElementsByTagName</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="domdocument.importnode.html">DOMDocument::importNode</a></div>
 <div class="up"><a href="class.domdocument.html">DOMDocument</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
